package cn.bonoon.kernel.descriptors.impl;

import java.lang.reflect.Field;

import cn.bonoon.kernel.descriptors.EmbeddedPropertyAccessor;
import cn.bonoon.kernel.descriptors.OnePropertyAccessor;

public class OnePropertyAccessorImpl extends AbstractEntityPropertyAccessor implements OnePropertyAccessor{
	/**
	 * <pre>
	 * 如果该属性不维护关联关系，这里应该指明是由对方的哪个属性来维护关联关系；
	 * 以后可以考虑使用这一属性来维护关联关系
	 * </pre>
	 */
	private final String relationshipFieldName;
	
	public OnePropertyAccessorImpl(Class<?> cls, String mappedName,
			Field field, EmbeddedPropertyAccessor embeddedProperty, String relationshipFieldName) {
		super(cls, mappedName, field, embeddedProperty);
		this.relationshipFieldName = relationshipFieldName;
	}

	@Override
	public boolean isAssignableFrom(Class<?> objectClass) {
		return type.isAssignableFrom(objectClass);
	}
	
	@Override
	public boolean isMaintainer() {
		return relationshipFieldName == null || relationshipFieldName.isEmpty();
	}

}
